package org.example.datajpa2;

import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.sql.Timestamp;
import java.util.List;

public interface StatusRepository extends CrudRepository<Status, Integer>, PagingAndSortingRepository<Status, Integer> {
    List<Status> findByAuthor(String author);
    List<Status> findByLikesGreaterThan(int likes);
    List<Status> findByContentContaining(String keyword);
    List<Status> findByAuthorAndCreateTimeBeforeOrderByCreateTime(String author, Timestamp time);

    @Query("select s from Status s where month(s.createTime) = ?1")
    List<Status> findByMonth(int month);

    @Transactional
    int deleteByAuthor(String author);
}
